#include <iostream>
#include <cstring>
using namespace std;

const int N = 1e6 + 10;
char s[N];
int dp[N];

int dfs(int i)
{
    if (dp[i] != -1) return dp[i];
    if (s[i] == '(' && s[i + 1 + dfs(i + 1)] == ')'
        || s[i] == '[' && s[i + 1 + dfs(i + 1)] == ']') {
        return dp[i] = dfs(i + 1) + 2 + dfs(i + 2 + dfs(i + 1));
    }
    return dp[i] = 0;
}

int main()
{
    cin >> s;
    int n = strlen(s);

    memset(dp, -1, sizeof dp);
    int ans = 0, pos = 0;
    for (int i = 0; i < n; i++) {
        dfs(i);
        if (dp[i] > ans) {
            ans = dp[i];
            pos = i;
        }
    }

    for (int i = pos; i < pos + ans; i++) {
        cout << s[i];
    }
    cout << endl;

    return 0;
}